import java.util.Arrays;
import java.util.List;

public class DiscountPromotionCalculator implements PromotionCalculator{
    private static final SalesPromotion salesPromotion = new SalesPromotion("50% Discount On Specified Items",
            "Half price for certain dishes", Arrays.asList("ITEM0001","ITEM0022"));

    public PromotionResult calculate(List<OrderItem> orderItems) {
        double savedAmount = orderItems.stream().filter(item -> salesPromotion.getRelatedItems().contains(item.getItemId()))
                .map(OrderItem::getAmount).reduce(Double::sum).orElse((double) 0) * 0.5;
        return new PromotionResult(savedAmount, salesPromotion);
    }
}
